package com.im.service.websocket.message.enums;

import com.im.service.exception.BusinessException;

import java.util.Arrays;

import static com.im.service.exception.ErrorCode.UNSUPPORTED_MESSAGE_TYPE;

public enum MessageType {
    DIRECT_MESSAGE,
    GROUP_MESSAGE;

    public static MessageType from(String messageType) {
        return Arrays.stream(MessageType.values())
                .filter(type -> type.name().equals(messageType)).findFirst().orElseThrow(() -> new BusinessException(UNSUPPORTED_MESSAGE_TYPE));
    }
}
